<?php

class Core_Backend_Component_Customer_View_Product_Create extends Core_Backend_Share_View_Form {

    protected function buildToolbar($toolbar) {
        $group = $toolbar->createGroup('back');
        $group->addLink($this->getHistoryUrl('customer/product/index'), $this->__('share.button.back'));
        $group = $toolbar->createGroup('save');
        $group->addButton($this->__('share.button.submit'))
                ->bindEvent('click', "Kdf.Ui.getForm('" . $this->getForm()->getId() . "').submit('" . $this->getUrl(NULL, 'submit') . "')");
        $group->addButton($this->__('share.button.apply'))
                ->bindEvent('click', "Kdf.Ui.getForm('" . $this->getForm()->getId() . "').submit('" . $this->getUrl(NULL, 'apply') . "')");
        $group->addButton($this->__('share.button.save'))
                ->bindEvent('click', "Kdf.Ui.getForm('" . $this->getForm()->getId() . "').submit('" . $this->getUrl(NULL, 'save') . "')");
        parent::buildToolBar($toolbar);
    }

    protected function buildForm($form) {
        $entity = $this->getModel(NULL);
        $form->setAction($this->getUrl())
                ->setId('product_form')
                ->addHiddenField('id', 'product[id]')
                ->addHiddenField('poi_id', 'product[poi_id]', $this->getShop()->getId());
        $form->addTextboxField($this->__('catalogue.label.name'), 'name', 'product[name]', TRUE)
                ->addValidateRule('required');
        $form->addComboTreeField($this->__('catalogue.label.category_name'), 'category_ids', "product[category_ids][]", TRUE)
                ->bindData($this->getCategories(), 0, array('valueKey' => 'code', 'textKey' => 'name', 'parentKey' => 'parent_code', 'childKey' => 'code'))
                ->setSize(8)
                ->setMultiple(TRUE);
        $form->addTextboxField($this->__('share.label.tag'), 'tag', 'product[tag]');
        $form->addFileBrowserField($this->__('catalogue.label.picture'), 'picture', 'product[picture]')
                ->setPath('pub/media/road/' . $this->getShop()->getRoadId() . '/' . $this->getShop()->getId() . '/product')
                ->setFileType('image')
                ->setCallback('selectProductPictute');
        $form->addTextareaField($this->__('catalogue.label.introduction'), 'introduction', 'product[introduction]');
        $form->addEditorField($this->__('catalogue.label.detail'), 'detail', 'product[detail]')->getForm();
        $form->createTab('base_option', $this->__('customer.label.base_information'), array('field_name','field_category_ids','field_tag','field_picture','field_introduction'));
        $form->createTab('content_option', $this->__('customer.label.detailed_information'), array('field_detail'));
        
        if (!is_null($entity)) {
            $form->bindData($entity->getAllData());
        }
        parent::buildForm($form);
    }

}